<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
   
       
        $this->display();
    }
    public function checkLogin(){
       session('flag',null);
        $code=I('post.verify');
       
        if(!$this->check_verify($code))$this->error('验证码错误');

        $admin=M('admins');
        $map   =   array();
        $map['admin_name']	= I('post.username');
        $map['password']	= md5(I('post.password'));
       
        $res=$admin->where($map)->select();
        if($res==null){
            $this->error('用户名密码错误');
        }else {
            session("flag","logok");
            redirect('count');
        }
    }
   public function _initialize(){
      /* //只要不是显示登录页面和处理登录、验证码这些，其他情况都要进行session验证。
      if(ACTION_NAME!='index' && ACTION_NAME!='checkLogin'&& ACTION_NAME!='verify'){
               //redirect('index');
           }*/
           if(ACTION_NAME != 'index' && ACTION_NAME != 'checkLogin'&& ACTION_NAME!='verify'){
            if(null == session('flag') || session('flag') != 'logok'){
                redirect('index');
            }
        }
       }
   
 function check_verify($code, $id = ''){
        $verify = new \Think\Verify();
        return $verify->check($code, $id);
    }
    public function count()
    {
          if(session('?flag')) {
       
            $users = M('users');
            $count1 = $users->count();
            $this->count1 = $count1;
            $meishis = M('meishis');
            $count2 = $meishis->count();
            $this->count2 = $count2;
            $foods = M('foods');
            $count3 = $foods->count();
            $this->count3 = $count3;
            
            $this->display();
              } else {
            echo'没有登录';
        }
        
     }
    public function verify(){

        ob_clean();
//        $config =    array(
//            'fontSize'    =>    30,    // 验证码字体大小
//            'length'      =>    3,     // 验证码位数
//            'useNoise'    =>    false, // 关闭验证码杂点
//            //'fontttf' => 'msyhbd.ttf',
//           
//
//            'useImgBg' => false,
//            //'useZh' => true,
//        );
//        $Verify = new \Think\Verify($config);
        $Verify = new \Think\Verify();
        $Verify->entry();
        
    }

  public function signout(){
        if(session('?flag')){
            session('flag',null);
        }
        redirect('index');
    }
}

